#!/bin/bash

Green=$'\e[1;32m'
Normal=$'\e[0m'

VER=`cat ../core/package.json | grep version`
VER=${VER#*:*\"}
VER=${VER%\.*}

OLDVER=`cat ../dk/ver`

if [[ $VER == $OLDVER ]]
then
    echo "====skip===============$Green$VER$Normal"
    exit
fi

echo "===================gline : $OLDVER => $Green$VER$Normal"
echo

#########################################################

ETAG=${VER//\./dot}

echo $VER > ../dk/ver

rm -rf ./build
cp -r ../core/build .

cat > ./default.conf <<EOF
server {
    listen       9000;
    server_name  localhost 127.0.0.1;

    root   /usr/share/nginx/html;
    index  index.html index.htm;

    add_header Cache-Control "no-cache";
    add_header ETag "$ETAG";

    location / {
        try_files \$uri \$uri/ @router;
    }

    location @router {
        rewrite ^.*$ /index.html last;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}
EOF

#########################################################

docker build -t gline:$VER .

echo
echo "build docker : $Green gline:$VER $Normal"
echo

CUR=`date +%H:%M:%S`
echo "finish time: $Green$CUR$Normal"
echo
